package com.itheima.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitmaqConfig {  
  
    /**  
     * 延时交换机，交换机类型为CustomExchange  
     */
    @Bean
    public CustomExchange customExchange() {
        Map<String, Object> args = new HashMap<>();
        //延时交换机一定要设置x-delayed-type属性  
        args.put("x-delayed-type", "direct");  
        //第二个参数type需要设置成x-delayed-message  
        return new CustomExchange("wmnews_delay_exchange", "x-delayed-message", true, false, args);
    }  
  
  
    /**  
     * 延时队列  
     *  
     * @return
     * */
    @Bean
    public Queue delayQueue() {
        return new Queue("wmnews_delay_queue", true);
    }  
  
    /**  
     * 延时队列绑定交换机  
     *  
     * @return     */
    @Bean
    public Binding delayBinding() {
        return BindingBuilder.bind(delayQueue()).to(customExchange()).with("wmnews_delay").noargs();
    }  
      
}